﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

using Aliphant.Common.Managers;
using Aliphant.IoC;
using Aliphant.Mvvm.XEvent.Interface;
using Aliphant.Mvvm.XEvent.UI;
using Aliphant.UI.Services;
using Aliphant.UI.Windows;

namespace Aliphant.Windows.ViewModels
{
    public class SettingPageViewModel : BindableBase, INavigate
    {
        private ThemeService _themeService;
        private bool _canSetTheme;

        public SettingPageViewModel()
        {
            _themeService = IoCServer.Container.Resolve<ThemeService>();
            _canSetTheme = true;
            //_themeSetting = (int)ConfigManager.Instance.Settings.AppearanceType;
        }

        private int _themeSetting;
        public int ThemeSetting
        {
            get => _themeSetting;
            set
            {
                SetProperty(ref _themeSetting, value);
                SetTheme(value);
            }
        }

        private bool _isThemeVisible;
        public bool IsThemeVisible
        {
            get => _isThemeVisible;
            set
            {
                SetProperty(ref _isThemeVisible, value);
                ConfigManager.Instance.Settings.ThemeVisible = value;
                GlobalProperty.SetThemeVisible(value);
            }
        }

        private bool _isExitNotify = false;
        public bool IsExitNotify
        {
            get => _isExitNotify;
            set
            {
                SetProperty(ref _isExitNotify, value);
                ConfigManager.Instance.Settings.ExitNotify = value;
            }
        }

        private void SetTheme(int value)
        {
            if (!_canSetTheme)
            {
                _canSetTheme = true;
                return;
            }

            ConfigManager.Instance.Settings.AppearanceType = (Datas.AppearanceType)value;
            _themeService.ApplyTheme(value);
        }

        public void OnNavigateTo(Datas.NavigateParameter navigateParameter)
        {
            _canSetTheme = ConfigManager.Instance.Settings.ThemeVisible;
            ThemeSetting = (int)ConfigManager.Instance.Settings.AppearanceType;
            IsExitNotify = ConfigManager.Instance.Settings.ExitNotify;
        }
    }
}
